// designed by Leuting 2008.3.19 to extract image feature for general purpose
// features:
//      local/global gray histogram

#ifndef _H_IMAGE_FEATURE_LT
#define _H_IMAGE_FEATURE_LT

#include   <direct.h>

#include <string>
#include <stdio.h>
#include <vector>

using namespace std;

#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/core/core_c.h>

#include "gabor/gabor.h"
//#include "sift/sift.h"
//#include "FeaSaveYNLi.h"

#ifndef PI
#define PI CV_PI//3.1415926
#endif

#define MAX_SIZE_YNLI 120

const double Sigma=PI*2;
const double F = sqrt(2.0);
const int frequency_select[]={-5,-4,-3,-2,-1,0,1,2};
const float max_mag[32]={1.367894,0.218879,0.002649,0.001030,0.459217,0.003089,0.000052,0.000362,6.282719,0.000008,0.000002,0.000003,0.459217,0.003089,0.000052,0.000362,1.367894,0.218879,0.002649,0.001030,0.459217,0.003089,0.000052,0.000362,6.282719,0.000008,0.000002,0.000003,0.459217,0.003089,0.000052,0.000362};
Gabor* constructGaborsLT(int orientation, int frequency);
int constructGaborsLT(Gabor * gabors, const int frequency, const int orientation);
Gabor* loadGaborsLT(int orientation, int frequency);
////////////////////////////////////////////////////////////////////

// extract gray histogram from RGB image file (name) to histogram file (name) 
int ExtractGrayHist(const char* imageFilename, const char* histoFilename
, const int nGridV, const int nGridH, const int nHistL);
// extract gray histogram from RGB/gray image (IplImage*) to histogram file (float*) 
int ExtractGrayHist(IplImage*   ptImage, float *fea
, const int nGridV, const int nGridH, const int nHistL);
// extract gray histogram from RGB/gray image file (name) to histogram file (float*) 
int ExtractGrayHist(const char* imageFilename, float *fea
, const int nGridV, const int nGridH, const int nHistL);

int ExtractColorFea(string imageFilename, string colorFilename
, int nGridV, int nGridH);

// gabor features 
int ExtractGaborFea(string imageFilename, string gaborFilename
, int nGridV, int nGridH, int nGaborO, int nGaborF);
// frequency * orientation * ( grid_vertival * grid_horizontal * mean )
int ExtractGaborFea(const char* imageFilename, const char* gaborFilename, Gabor* gabors
, const int nGaborF, const int nGaborO, const int nGridV, const int nGridH);
// suggested by ynli: overlap grids (slice)
int ExtractGaborSlice(const char* imageFilename, const char* gaborFilename, Gabor* gabors
, const int nGaborF=4, const int nGaborO=8, const int nSliceR=10);
int ExtractGaborSlice(IplImage* ptImage, float**fea, int&dim1,int &dim2, Gabor* gabors
, const int nGaborF=4, const int nGaborO=8, const int nSliceR=10, const int max_size = 120);
// interface for ynli: overlap grids (slice)
int ExtractGaborSlice(IplImage* ptImage, float***fea, int&dim1,int &dim2, Gabor* gabors
, const int nGaborF=4, const int nGaborO=8, const int nSliceR=10);

int ExtractColorGaborSlice(IplImage* ptImage, float***fea, int&dim1,int &dim2, Gabor* gabors
, const int nGaborF=4, const int nGaborO=8, const int nSliceR=10);

// sift features
// extract sift from file imgName to file rstName
//int ExtractSiftFea(const char* str_src, const char* str_dst);

#endif
